package it.polito.connectedcar.general.network;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.SocketException;

/**
 * This class represents a generic socket in ConnectedCar system , used by all
 * the entities ( TCC, vehicles, Traffic Lights ) to send and receive messages
 * on the underlying network. This abstraction is used to potentially apply
 * delys in the sending and receiving process in order to simulate network
 * delays
 * 
 * @author Nicola Aresta
 * 
 */
public abstract class ConnectedCarSocket extends DatagramSocket {

	public ConnectedCarSocket() throws SocketException {
		super();
	}

	public ConnectedCarSocket(int port) throws SocketException {
		super(port);
	}

	public ConnectedCarSocket(SocketAddress address) throws SocketException {
		super(address);
	}

	/**
	 * DatagramSocket abstraction for message sending in order to decouple the
	 * DataGramSocket implementation and the system-dependent implementation
	 * 
	 * @param p
	 * @throws IOException
	 */
	public abstract void sendMessage(final DatagramPacket p) throws IOException;

	/**
	 * Many scenario apply to the Connectedcars system ( simulated and real).
	 * Each scenario will use Addresses in different ways depending on the
	 * needs. An address can be considered equal to another one depending on the
	 * running scenario. ( hostname and port , only port...)
	 * 
	 * @param address
	 * @return
	 */
	public abstract boolean isSameAddress(InetSocketAddress address);
}
